package com.bank.Utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @ProjectName: bankSystem
 * @Author: Jsx
 * @Time: 2020/9/12 16:38
 * @Description:
 */
public class MybatisUtils {
    /**
     * 在这个里面去写Sqlsession
     */
    private static SqlSessionFactory factory = null;
    static {
        Reader reader= null;
        try {
            reader = Resources.getResourceAsReader("mybatis.xml");
            factory = new SqlSessionFactoryBuilder().build(reader);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static SqlSession getSession(){
        return factory.openSession();
    }
}
